﻿using System.Windows;
using System.Windows.Controls;
using XEvolve.Core.Runtime;
using XEvolve.Core.Runtime.Attributes;
using XEvolve.Presentation;

namespace Demo.Client.Presentation
{
    /// <summary>
    /// Interaction logic for Main.xaml
    /// </summary>
    public partial class Main
    {
        private readonly IThemeManager themeManager;

        public Main(IThemeManager themeManager, [ExtensionPoint("xevolve.themes")]IExtensionPoint themes)
        {
            this.themeManager = themeManager;
            InitializeComponent();
            chooser.ItemsSource = themes.ExtensionIdentifiers;
            chooser.SelectionChanged += OnChooseNewTheme;
            colorChooser.SelectionChanged += OnChooseNewColorSchema;
            target.Click += OnTargetClicked;
        }

        private void OnTargetClicked(object sender, RoutedEventArgs e)
        {            
        }

        private void OnChooseNewColorSchema(object sender, SelectionChangedEventArgs e)
        {
            var selectedTheme = (string)chooser.SelectedItem;
            var selectedColor = (string)colorChooser.SelectedItem;
            themeManager.ApplyTheme(selectedTheme, selectedColor);
        }

        private void OnChooseNewTheme(object sender, SelectionChangedEventArgs e)
        {
            var selectedTheme = (string)chooser.SelectedItem;
            colorChooser.ItemsSource = themeManager.GetApplicableColorSchema(selectedTheme);            
            themeManager.ApplyTheme(selectedTheme);
        }
    }
}
